<!--#include file="common/header.html"-->
<body>
    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <!--头部搜索-->
                <section class="panel panel-padding">
                    <form class="layui-form" action="/education/admin/message">
                        <div class="layui-form">
                            <div class="layui-inline">
                                <select name="_query.type">
                                    <option value="">通知类别</option>
                                    <option value="sys_msg">系统通知</option>
                                    <option value="finish_order">订单通知</option>
                                    <option value="deliver_goods">发货通知</option>
                                </select>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="_query.keyword" placeholder="关键字">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button lay-submit class="layui-btn" lay-filter="search" id="search">查找</button>
                            </div>
                        </div>
                    </form>
                </section>

                <!--列表-->
                <section class="panel panel-padding">

                    <div class="group-button">
                        <button class="layui-btn layui-btn-small modal-catch"
                                data-params='{"content":".add-subcat", "title":"添加","type":"1", "area":"600px,580px", "maxmin":"true"}'>
                            <i class="iconfont">&#xe649;</i> 添加
                        </button>
                        <!--<button class="layui-btn layui-btn-small modal-catch" data-name="messageData"
                                data-params='{"content": ".add-subcat","area":"600px,400px","title":"编辑","key":"ids=","data":"url=\"/education/admin/message/update\" ","type":"1"}'>
                            <i class="iconfont">&#xe653;</i>编辑
                        </button>-->
                        <button class="layui-btn layui-btn-small layui-btn-danger ajax-all" data-name="checkbox" data-params='{"url": "/education/admin/message/delete"}'>
                            <i class="iconfont">&#xe626;</i> 删除
                        </button>
                    </div>
                    <div id="list" class="layui-form"></div>

                    <div class="text-right" id="page"></div>
                </section>
            </div>
        </div>
    </div>
    <div class="add-subcat">
        <form class="layui-form layui-form-pane" action="/education/admin/message/save">
            <div class="layui-form-item">
                <label class="layui-form-label">类别</label>
                <div class="layui-input-inline">
                    <select name="type" id="type" lay-filter="filter">
                        <option value="sys_msg">系统通知</option>
                        <option value="finish_order">订单通知</option>
                        <option value="deliver_goods">发货通知</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">主题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" required
                           jq-verify="required" jq-error="请输入" class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">内容</label>
                <div class="layui-input-block">
                    <textarea name="content" required jq-verify="required" jq-error="请输入值"
                              class="layui-textarea "></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">收件人</label>
                <div class="layui-input-block">
                    <input type="hidden" name="to_userid" id="toUserId">
                    <input type="text" name="to_username" placeholder="请输入用户名或手机号" id="autocompleteInput"
                          autocomplete="false" class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" jq-submit jq-filter="submit" before-fun="beforeSubmit();">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>


</body>
<!--#include file="message-list.html"-->
<script src="../js/layui/layui.js"></script>
<script type="text/javascript" src="../js/lib/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../js/lib/bootstrap.autocomplete.js"></script>
<!--#include file="common/version.html"-->
<script>
    layui.use('user_list');
    layui.use(['form'], function () {
        var form = layui.form();
        form.on('select(filter)', function(data){
            if(data.value == 'sys_msg'){
                $('#autocompleteInput').parent().parent().hide();
            }else {
                $('#autocompleteInput').parent().parent().show();
            }
        });
    });
    $(function(){
        $('#autocompleteInput').parent().parent().hide();
        $('#autocompleteInput').autocomplete({
            source:function(query,process){
                var matchCount = this.options.items;//返回结果集最大数量
                $.post("/education/api/user",{"_query.keyword":query},function(respData){
                    console.log(respData);
                    if(respData.code == 200) {
                        return process(respData.data);
                    }
                });
            },
            formatItem:function(item){
                var mobile = item["mobile"] || '';
                var name = item["name"] || '';
                var username = item["username"] || '';
//                return username +"("+ name +"，"+ mobile +") - "+ level;
                return name +"("+ username + ")";
            },
            setValue:function(item){
                return {'data-value':item["name"],'real-value':item["id"]};
            }
        });
    });

    function beforeSubmit(){
        $('#toUserId').val($('#autocompleteInput').attr('real-value'));
    }

    function viewReadDetail(id, title) {
        var index = layer.open({
            type: 2,
            content: "message-read.html?msgId=" + id, "title": "【"+ title +"】签收情况", "full":"true"
        });
        layer.full(index);
    }

</script>

</html>